package com.ruoyi.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AssetStock;
import com.ruoyi.asset.service.IAssetStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点任务Controller
 * 
 * @author asset
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/asset/stock")
public class AssetStockController extends BaseController
{
    @Autowired
    private IAssetStockService assetStockService;

    /**
     * 查询盘点任务列表
     */
    @GetMapping("/my")
    public TableDataInfo my(AssetStock assetStock)
    {
        assetStock.setUserId(SecurityUtils.getUserId());
        startPage();
        List<AssetStock> list = assetStockService.selectAssetStockList(assetStock);
        return getDataTable(list);
    }

    /**
     * 查询盘点任务列表
     */
    @PreAuthorize("@ss.hasPermi('asset:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetStock assetStock)
    {
        startPage();
        List<AssetStock> list = assetStockService.selectAssetStockList(assetStock);
        return getDataTable(list);
    }

    /**
     * 导出盘点任务列表
     */
    @PreAuthorize("@ss.hasPermi('asset:stock:export')")
    @Log(title = "盘点任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetStock assetStock)
    {
        List<AssetStock> list = assetStockService.selectAssetStockList(assetStock);
        ExcelUtil<AssetStock> util = new ExcelUtil<AssetStock>(AssetStock.class);
        util.exportExcel(response, list, "盘点任务数据");
    }

    /**
     * 获取盘点任务详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetStockService.selectAssetStockById(id));
    }

    /**
     * 新增盘点任务
     */
    @PreAuthorize("@ss.hasPermi('asset:stock:add')")
    @Log(title = "盘点任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetStock assetStock)
    {
        assetStock.setCreateBy(SecurityUtils.getUsername());
        return toAjax(assetStockService.insertAssetStock(assetStock));
    }

    /**
     * 修改盘点任务
     */
    @PreAuthorize("@ss.hasPermi('asset:stock:edit')")
    @Log(title = "盘点任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetStock assetStock)
    {
        assetStock.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(assetStockService.updateAssetStock(assetStock));
    }

    /**
     * 删除盘点任务
     */
    @PreAuthorize("@ss.hasPermi('asset:stock:remove')")
    @Log(title = "盘点任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetStockService.deleteAssetStockByIds(ids));
    }


    /**
     * 提交盘点任务
     */
    @PreAuthorize("@ss.hasPermi('asset:stock:edit')")
    @GetMapping(value = "/submit/{id}")
    public AjaxResult submit(@PathVariable("id") Long id)
    {
        return success(assetStockService.submitAssetStock(id));
    }
}
